package com.sl.biz.modular.process.dao.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.process.dao.domain.dto.ProcessCompVersionBuildDTO;
import com.sl.biz.modular.process.dao.domain.entity.ProcessCompVersionBuildDO;
import com.sl.biz.modular.process.dao.mapper.ProcessCompVersionBuildMapper;
import com.sl.biz.modular.process.dao.service.ProcessCompVersionBuildDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ProcessCompVersionBuildDaoServiceImpl extends ServiceImpl<ProcessCompVersionBuildMapper, ProcessCompVersionBuildDO> implements ProcessCompVersionBuildDaoService {
    @Override
    public ProcessCompVersionBuildDTO queryLastBuild(String compCode, String compVersion) {
        LambdaQueryWrapper<ProcessCompVersionBuildDO> wrapper = Wrappers.lambdaQuery();
//        wrapper.eq(ProcessCompObjectDO::getDeleted, DataBaseConstant.DELETE_VALID);
        wrapper.eq(ProcessCompVersionBuildDO::getCompCode, compCode);
        wrapper.eq(ProcessCompVersionBuildDO::getCompVersion, compVersion);
        wrapper.orderByDesc(ProcessCompVersionBuildDO::getBuildStartDate);
        wrapper.last("limit 1");
        ProcessCompVersionBuildDO list = baseMapper.selectOne(wrapper);
        return BeanUtil.copyProperties(list, ProcessCompVersionBuildDTO.class);
    }

    @Override
    public Boolean removeByCompCode(String compCode) {
        LambdaQueryWrapper<ProcessCompVersionBuildDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProcessCompVersionBuildDO::getCompCode, compCode);
        return super.remove(queryWrapper);
    }

    @Override
    public Boolean removeByCompCodeAndVersion(String compCode, String version) {
        LambdaQueryWrapper<ProcessCompVersionBuildDO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ProcessCompVersionBuildDO::getCompCode, compCode);
        wrapper.eq(ProcessCompVersionBuildDO::getCompVersion, version);
        return super.remove(wrapper);
    }
}
